package com.foreknow.controller;

import com.foreknow.model.Gusetbook;
import com.foreknow.service.impl.GusetbookeServiceInpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet(name = "UpdateServlet")
public class UpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html;charset=utf-8");
            request.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        GusetbookeServiceInpl inpl = new GusetbookeServiceInpl();
        Gusetbook gusetbook = new Gusetbook();
         gusetbook.setName(request.getParameter("name"));
         gusetbook.setPhone(request.getParameter("phone"));
         gusetbook.setEmail(request.getParameter("email"));
         gusetbook.setTitle(request.getParameter("title"));
         gusetbook.setContent(request.getParameter("content"));
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        gusetbook.setCreatedtime(sdf.format(new Date()));
         String id=request.getParameter("user");
         out.println(id);
        int i = inpl.updateUser(Integer.parseInt(request.getParameter("user")), gusetbook);
        if (i>0){
            request.getRequestDispatcher("/manager?q=list").forward(request,response);
        }else {
            out.println("default");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
